local sk__yansha = fk.CreateSkill {

  name = "sk__yansha",

  tags = {},

}



sk__yansha:addEffect(fk.EventPhaseStart, {
  name = "sk__yansha",
  anim_type = "control",
  expand_pile = "sk_sr__zhangliao_yan",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__yansha.name) then
      return target == player and player.phase == Player.Finish and not player:isKongcheng()
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    cards = room:askForCard(player, 1, 1, false, sk__yansha.name, true, ".", "#sk__yansha-put")
    if #cards > 0 then
      event:setCostData(self, cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:addToPile("sk_sr__zhangliao_yan", event:getCostData(self), false, sk__yansha.name, player.id)
  end,
})
sk__yansha:addEffect(fk.TargetSpecified, {
  name = "sk__yansha",
  anim_type = "control",
  expand_pile = "sk_sr__zhangliao_yan",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__yansha.name) then
      return target ~= player and data.card and data.card.trueName == "slash" and not target.dead and
          not target:isKongcheng() and
          #player:getPile("sk_sr__zhangliao_yan") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    cards = room:askForCard(player, 1, 1, false, sk__yansha.name, true, ".|.|.|sk_sr__zhangliao_yan",
      "#sk__yansha-invoke::" .. target.id, "sk_sr__zhangliao_yan")
    if #cards > 0 then
      event:setCostData(self, cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, { target.id })
    room:moveCardTo(event:getCostData(self), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, sk__yansha.name, nil, true,
      player.id)
    if not player.dead and not target.dead and not target:isKongcheng() then
      local cards = room:askForCardsChosen(player, target, 1, 2, "h", sk__yansha.name, "#sk__yansha-prey::" ..
        target.id)
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, sk__yansha.name, nil, false, player)
    end
  end,
})

return sk__yansha
